package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.Employee;
import com.sky.myenum.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {


    /**
     * 菜品的分页查询
     * @param name
     * @param categoryId
     * @param status
     * @return
     */
    List<DishVO> selectByPage(String name, Integer categoryId, Integer status);


    @Select("select * from dish where id = #{id}")
    Dish selectById(Long id);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> selectFlavorsByDishId(Long id);


    @Update("update dish_flavor set value = #{flavors} where dish_id = #{dishId}")
    void updateFlavorsByDishId(List<DishFlavor> flavors, Long dishId);

    @AutoFill(OperationType.UPDATE)
    @Update("update dish set name = #{name},category_id = #{categoryId}, price = #{price},image=#{image}," +
            "description=#{description},update_time=#{updateTime},update_user=#{updateUser} where id =#{id}")
    void update(Dish dish);


    void deleteByIds(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    @Update("update dish set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id = #{id}")
    void changeStatus(Dish dish);



    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);


    List<Dish> selectByCategoryId(Long categoryId,String name);

    @Select("select * from dish where id = #{dishId}")
    Dish getById(Long dishId);
}
